package com.example.tweetfeed;

import org.json.JSONObject;

import android.graphics.Bitmap;
import android.os.Parcel;
import android.os.Parcelable;

public class Tweet implements Parcelable{
	
	private String mUser = "";
	private String mText = "";
	private String mImageUrl = "";
	private Bitmap mImage = null;
	
	public Tweet(JSONObject feed) throws Exception {
		mUser = feed.getJSONObject("user").getString("name");
		mText = feed.getString("text");
		mImageUrl = feed.getJSONObject("user").getString("profile_image_url_https");
		mImage = null;
	}
	
	public Tweet(Parcel p) {
		readFromParcel(p);
	}
	
	public String getText() {
		return mText;
	}
	public String getUserName() {
		return mUser;
	}
	
	public String getImageUrl() {
		return mImageUrl;
	}
	
	public Bitmap getImage() {
		return mImage;
	}
	
	public void setImage(Bitmap loaded) {
		mImage = loaded;
	}

	@Override
	public int describeContents() {
		return 0;
	}

	@Override
	public void writeToParcel(Parcel dest, int flags) {
		dest.writeString(mUser);
		dest.writeString(mText);
		dest.writeString(mImageUrl);
		dest.writeValue(mImage);
		
	}
	
	private void readFromParcel(Parcel src) {
		mUser = src.readString();
		mText = src.readString();
		mImageUrl = src.readString();
		mImage = src.readParcelable(Bitmap.class.getClassLoader());
	}
	
	public static final Parcelable.Creator<Tweet> CREATOR
    = new Parcelable.Creator<Tweet>() {
        public Tweet createFromParcel(Parcel in) {
            return new Tweet(in);
        }
 
        public Tweet[] newArray(int size) {
            return new Tweet[size];
        }
    };
}
